package com.hxzy.boot.pojo;

/**
 * @author wzm
 * @create 2023-09-25 11:17
 * project_name:javaweb2308
 */
//同一结果返回类  将要返回的数据封装在该类中 同一返回此类即可
public class Result {
    //将要返回给客户端的信息定义为属性
    //状态码 0表示失败  1表示成功
    private  Integer code;

    //描述信息 描述字符串
    private String msg;

    //返回数据 string 对象  list
    private Object data;

    public Result() {
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    //成功
    //增删改成功
    public static Result success() {
        return new Result(1, "success", null);
    }

    //查询成功
    public static Result success(Object data) {
        return new Result(1, "success", data);
    }

    //失败
    public static Result error(String msg) {
//        if(msg == null){
//            msg = "未知错误";
//        }
        return new Result(0, msg, null);
    }
}
